

clear all
cap log close
set more off
set matsize 1600
set mem 100m

global ROOT ""
global data "$ROOT/Data"
global dofiles "$ROOT/DoFiles"
global tables "$ROOT/Tables"
global figures "$ROOT/Figures"

use "$data/analysisdata_chats.dta", clear

*-------------------------------------------------------------------
*Deciding on the zones and villages
*-------------------------------------------------------------------
global ourcluster "zone_o"

*Village variable for the village fixed effects
*vill1 is for the village in the first wave
local village "vill1"

*------------------------------
* Creating the summary index
*------------------------------
* Step 1: Standardising the variables to create effect size
foreach y of varlist cre_a local_a job_a sch_a planni_a nutr_a preg_a  cre_n local_n job_n sch_n planni_n nutr_n preg_n {
sum `y'
local m = r(mean)
sum `y' if wg_o==0
local s = r(sd)
gen std_`y' = (`y' - `m')/`s'
}


regress std_cre_a std_local_a std_job_a std_sch_a std_planni_a std_nutr_a std_preg_a
keep if e(sample)


*Step 2: Creating the weights matrix
cap mata clear
mata
st_view(X=., ., ("std_cre_a", "std_local_a", "std_job_a", "std_sch_a"))
Y = invsym(X'X)			/* Computing the inverse of the covariance matrix */
b = rowsum(Y)			/* Getting the sum across rows */
c= colsum(b)
weights = b/c
st_matrix("weights", weights)


**Health chats only
st_view(X=., ., ("std_planni_a", "std_nutr_a", "std_preg_a"))
Y = invsym(X'X)			/* Computing the inverse of the covariance matrix */
b = rowsum(Y)			/* Getting the sum across rows */
c= colsum(b)
/* Weights matrix is now */
weights = b/c
st_matrix("weights5", weights)

end



foreach y of numlist 1/4 {
local we`y' = weights[`y',1]
}

gen non_health_chats = `we1'*std_cre_a+`we2'*std_local_a+`we3'*std_job_a+`we4'*std_sch_a



* Creating the chats index

foreach y of numlist 1/4 {
local we`y' = weights5[`y',1]
}

gen health_chat_index = `we1'*std_planni_a+`we2'*std_nutr_a+`we3'*std_preg_a


mat drop weights weights5


*-----------------------------------------------------------------------------------------------------------
*Regression settings
*-----------------------------------------------------------------------------------------------------------
gen     last=1 if wave==2
replace last=0 if wave==1

gen days_oct2=days_oct*days_oct

*Specify the smallest education level as the base level
fvset base 0 edu

tab edu, gen(edu_)
tab month, gen(month_)

gen age2 = age^2


global regressors2 "wg_o edu_2 edu_3 edu_4 age age2 last month1 month2 month3 month4 month5 month8 month9 month10 numfem nummale"
global controls "z_sec z_married z_hhsize" 



matrix coeff1 = J(1,2,.)
matrix colnames coeff1 = "Health Chats" "Non-Health Chats" 
matrix CI1 = J(2,2,.)
matrix colnames CI1 = "Health Chats" "Non-Health Chats"
matrix rownames CI1 = ll95 ul95 

local i 0

foreach y in  health_chat_index non_health_chats   {
	local ++ i

reg `y' $regressors2 $controls, cluster(zone_o) 
matrix coeff1[1,`i']=e(b)[1,1]
boottest wg_o , boot(wild) seed(10101) bootcl($ourcluster)
matrix CI1[1,`i']=r(CI)[1,1]
matrix CI1[2,`i']=r(CI)[1,2]

}


set scheme s1mono

coefplot (matrix(coeff1[1,]), ci(CI1)),  xline(0)  ciopts(recast(rcap)) citop 
graph save "$revision_graphs/chats_treat_control", replace
graph export "$revision_graphs/chats_treat_control.pdf", replace






